/*******************************************************************************
* AW9523B - driver
* 16 channel breath LED/GPIO extender controler
* by longcd
*******************************************************************************/

#include "iic.h"
#include "AW9523B.h"


//IIC slave address
#define AW_FIX_ADDR	((aw_u8)0Xb0)		//fixed address
#define AW_AD1_AD0	((aw_u8)0 << 1)		//sub address decided by AD1,AD0 pin
#define AW_ADDR		(AW_FIX_ADDR | AW_AD1_AD0)

//R/W
#define AW_WRITE	0
#define AW_READ		1

//fixed ID
#define AW_ID		0X23

/*******************************************************************************
*
*/

/*	read register
 *	reg		: register address
 *	return	: register value
 */
aw_u8 AW9523_readReg(aw_u8 reg)
{
	aw_u8 val;

	IIC_start();
	IIC_WriteByte(AW_ADDR + AW_WRITE);
	IIC_WriteByte(reg);
	IIC_stop();
	IIC_start();
	IIC_WriteByte(AW_ADDR + AW_READ);
	val = IIC_ReadByte(NO_ACK);
	IIC_stop();
	return val;
}

/*	write register
 *	reg		: register address
 *	val		: register value
 */
void AW9523_writeReg(aw_u8 reg, aw_u8 val)
{
	IIC_start();
	IIC_WriteByte(AW_ADDR + AW_WRITE);
	IIC_WriteByte(reg);
	IIC_WriteByte(val);
	IIC_stop();
}
